package com.cmict.data.bpm.dal.mysql.definition;

import com.cmict.data.framework.common.pojo.PageResult;
import com.cmict.data.framework.mybatis.core.mapper.BaseMapperX;
import com.cmict.data.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cmict.data.bpm.controller.admin.definition.vo.task.TaskVariableExportReqVO;
import com.cmict.data.bpm.controller.admin.definition.vo.task.TaskVariablePageReqVO;
import com.cmict.data.bpm.dal.dataobject.definition.TaskVariableDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 流程变量 Mapper
 * @author liutao
 * @date 2022/6/6
 */
@Mapper
public interface TaskVariableMapper extends BaseMapperX<TaskVariableDO> {

    default PageResult<TaskVariableDO> selectPage(TaskVariablePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TaskVariableDO>()
                .likeIfPresent(TaskVariableDO::getName, reqVO.getName())
                .eqIfPresent(TaskVariableDO::getModelId, reqVO.getModelId())
                .eqIfPresent(TaskVariableDO::getProcessDefinitionId, reqVO.getProcessDefinitionId())
                .eqIfPresent(TaskVariableDO::getTaskId, reqVO.getTaskId())
                .eqIfPresent(TaskVariableDO::getRule, reqVO.getRule())
                .eqIfPresent(TaskVariableDO::getOptions, reqVO.getOptions())
                .betweenIfPresent(TaskVariableDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(TaskVariableDO::getId));
    }

    default List<TaskVariableDO> selectList(TaskVariableExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<TaskVariableDO>()
                .likeIfPresent(TaskVariableDO::getName, reqVO.getName())
                .eqIfPresent(TaskVariableDO::getModelId, reqVO.getModelId())
                .eqIfPresent(TaskVariableDO::getProcessDefinitionId, reqVO.getProcessDefinitionId())
                .eqIfPresent(TaskVariableDO::getTaskId, reqVO.getTaskId())
                .eqIfPresent(TaskVariableDO::getRule, reqVO.getRule())
                .eqIfPresent(TaskVariableDO::getOptions, reqVO.getOptions())
                .betweenIfPresent(TaskVariableDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(TaskVariableDO::getId));
    }

    @Select("${sql}")
    TaskVariableDO selectBpmtask(String sql);
}
